package es.efor.ics.gev.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The persistent class for the <b>TITULACIONES</b> database table.
 * 
 * @author dlisbona
 *
 */
@Entity
@Table(name = "TITULACIONES")
public class Titulacion extends BaseObject implements Serializable {

	// static data
	private static final long serialVersionUID = -969910613281692365L;

	// private instance data
	private Long id;
	private String nombreTitulacion; // required
	private boolean creditos;
	private TipoTitulacion tipoTitulacion;
	private Integer version;

	/**
	 * Construct an uninitialized <code>Titulacion</code> (for runtime proxy
	 * generation in Hibernate).
	 */
	protected Titulacion() {
	}

	// ********************** Accessor Methods ********************** //

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "TITULACION_ID")
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "NOMBRE_TITULACION", nullable = false)
	public String getNombreTitulacion() {
		return nombreTitulacion;
	}

	public void setNombreTitulacion(String nombreTitulacion) {
		this.nombreTitulacion = nombreTitulacion;
	}

	@Column(name = "CREDITOS")	
	public boolean isCreditos() {
		return creditos;
	}

	public void setCreditos(boolean creditos) {
		this.creditos = creditos;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TIPO_TITULACION_ID", nullable = true)
	@org.hibernate.annotations.ForeignKey(name = "FK_TITULACION_TIPO_TIT_ID")
	public TipoTitulacion getTipoTitulacion() {
		return tipoTitulacion;
	}

	public void setTipoTitulacion(TipoTitulacion tipoTitulacion) {
		this.tipoTitulacion = tipoTitulacion;
	}

	@Version
	@Column(name = "OBJ_VERSION")
	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	// ********************** Common Methods ********************** //

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Titulacion == false) {
			return false;
		}
		if (this == obj) {
			return true;
		}
		Titulacion rhs = (Titulacion) obj;
		return new EqualsBuilder().append(this.getNombreTitulacion(),
				rhs.getNombreTitulacion()).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder(17, 37).append(this.getNombreTitulacion())
				.toHashCode();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE).append(
				"nombreTitulacion", this.getNombreTitulacion()).toString();
	}

}
